home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Developer's Kit 1996
/
Delphi Developer's Kit 1996.iso
/
power
/
blade10
/
blabel.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-12-22
|
4KB
|
139 lines
{ TBlinkLabel Component v1.00 for Delphi - Freeware by Peak Computing
I wrote this label because I needed some blinking text on a form, it is a *VERY* simplistic
hack of TLabel, have fun with it!
The only new property added is "BlinkRate" this is the blinking speed of the text in milliseconds,
the lowest number is 100, highest is 65535. Note: If you set this value to zero (0) you will stop
the text from blinking, it checks to see if you stopped it, and if the text is currently "off" it
will make sure it is visible again before stopping.
Email help@peak.usa1.com if you have a question/bug/suggestion
}
unit Blabel;
interface
uses
Classes, Controls, Forms, StdCtrls, ExtCtrls, Graphics;
type
TBlinkLabel = class(TLabel)
private
{ Private declarations }
FBlinkRate:Word;
Timer1:TTimer;
Ready, Toggle:Boolean;
OldColor:TColor;
procedure DoBlink(Sender:TObject);
procedure SetBlinkRate(value:word);
protected
{ Protected declarations }
constructor Create(AOwner : TComponent); override;
procedure Loaded; override;
public
{ Public declarations }
published
{ Published declarations }
property BlinkRate:word read FBlinkRate write SetBlinkRate default 300;
end;
procedure Register;
implementation
{ Set the label's blinking rate }
procedure TBlinkLabel.SetBlinkRate(value:word);
begin
{ Is it 0? }
if (value=0) then
begin
{ It is, user wants the blinking to stop, check
and see if the text is currently invisible }
if (toggle) then
begin
{ It was invisible, turn it back on }
if (font.color=color) then
font.color:=oldcolor;
toggle:=not toggle;
end;
end { Don't allow a value lower than 100, lower doesn't work to well on some machines }
else if (value<100) then
value:=100;
FBlinkRate:=value;
{ Check to see if the timer is created before trying to assign a value }
if (Ready) then timer1.interval:=FBlinkRate;
end;
{ Handle timer event }
procedure TBlinkLabel.DoBlink(Sender:TObject);
begin
{ Do blinking }
if (toggle) then
begin
{ This "if" statement is to test and see if the user is trying to
change the label's color, if so, don't put back the old color over
the one he just set! }
if (font.color=color) then
font.color:=oldcolor;
toggle:=not toggle;
end
else
begin
oldcolor:=font.color;
font.color:=color;
toggle:=not toggle;
end;
end;
{ Create our component }
constructor TBlinkLabel.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
{ Set default blink-rate }
BlinkRate:=300;
invalidate;
end;
{ This is run when the component is loaded }
procedure TBlinkLabel.Loaded;
begin
inherited loaded;
{ Is it still in design-time? If so, exit.
(I found having it blink while designing was
annoying and messed up sometimes, so it only
blinks when the application is running)}
if (csDesigning in ComponentState) then exit;
{ Create timer and setup event }
timer1:=TTimer.create(self);
timer1.interval:=FBlinkRate;
timer1.ontimer:=DoBlink;
timer1.enabled:=true;
{ Init some varibles }
toggle:=false;
ready:=true;
end;
{ Register our component }
procedure Register;
begin
RegisterComponents('Standard', [TBlinkLabel]);
end;
end.